package cn.lghuntfor.commons.mybatis.plus.common;

import cn.lghuntfor.commons.common.async.AsyncUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;

/**
 * 数据库预热
 * @author liaogang
 * @date 2021/2/9 9:11
 */
@Slf4j
public class WarmUpService {

    @Autowired
    private WarmUpMapper warmUpMapper;

    @PostConstruct
    public void init() {
        AsyncUtils.run(this::warmUp);
    }

    public void warmUp() {
        try {
            log.info("db warm up, date = " + warmUpMapper.getDate());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

}
